Guides:SQL/How do I/PHP and MySQL

From CoderGuide

Jump to: navigation, search

Return to the SQL How Do I Index

Here is the new method for PHP5. Procedural method example:

<title>MySQL with PHP5 test</title>
$connect =mysqli_connect("server","username","password");
$result = mysqli_query($connect,"SELECT * FROM tt;");
<table border="1">
<tr><th>ID</th><th>Data A</th><th>Data B</th></tr>
while( $row = mysqli_fetch_array($result, MYSQLI_NUM)){
	foreach ($row as $col)
		print "<td>$col</td>";

MYSQLI_NUM tells mysqli_fetch_array to return a array referenced by numbers, MYSQLI_ASSOC tells it to use an associated array (referenced by labels, also incorrectly called a hash in Perl), and MYSQLI_BOTH is for those that can't make up their mind (allows you to refer to the elements by column ID or by the order in which they are returned by the query).

Personal tools