PHP and MySQLi SELECT query

By | November 9, 2012
Selec All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php 
$i = new mysqli('localhost', 'username', 'password', 'database');
 
if ($result = $i->query("SELECT * FROM tablename;") )
   {
      printf("Select returned %d rows.\n", $result->num_rows);
 
      if ($result->num_rows > 0)
         {
            while ($row = $result->fetch_object())
               {
                  print_r($row);
               }
         }
 
      $result->close();
   }
else
   {
      printf("%d : %s\n", $i->errno, $i->error);
   }
?>
Selec All Code:
1
2
3
4
if (!$i->query("INSERT INTO table VALUES(null, 'x','x','x');" ) ) 
   {
      /* Handle Error */
   }

or

Selec All Code:
1
2
3
4
5
6
7
8
if ($i->query("INSERT INTO table VALUES(null, 'x','x','x');" ) ) 
   {
      /* Handle Success */
   }
else
   {
      /* Handle Error */
   }
Category: PHP