below is my PHP code to display all the data in my database in a table..
if I use this code below to login and select DB rather than using PDO:
mysql_connect("localhost","root","12345678") or die(mysql_error());
mysql_select_db("clubresults") or die(mysql_error());
$query=mysql_query("SELECT * from events ORDER By EventID ASC") or die(mysql_error());
The output gives me a table with all the data listed correctly.
However If I use PDO.. it gives me this Error:
Warning: mysql_num_fields() expects parameter 1 to be resource, object given in C:\xampp\htdocs\clubresults\listevents.php on line 52
Warning: mysql_fetch_row() expects parameter 1 to be resource, object given in C:\xampp\htdocs\clubresults\listevents.php on line 58
Below is the full php code to grab data to and place in a table (Doesn't work) anyone able to point out where i have a mistake? because I can't seem to figure it out myself.. All suggestions are really appreciated! Thanks!
$pdo = new PDO('mysql:host=localhost;dbname=clubresults', 'root', '12345678');
#Set Error Mode to ERRMODE_EXCEPTION.
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query=$pdo->query('SELECT * from events ORDER By EventID ASC');
<<<<<<<<<<<<<<<<THIS BIT WORKS IF NOT USING PDO>>>>>>>>>>
$numfields = mysql_num_fields($query);
print("<table border=\"1\">\n<tr>\n");
for ($i=0; $i<$numfields; $i++) {
printf("<th>%s</th>\n", mysql_field_name($query,$i));
}
print("</tr>\n");
while ($row = mysql_fetch_row($query)) {
print("<tr>\n");
for ($i=0; $i<sizeof($row); $i++) {
printf("<td><a href=\"index.php?ID=%s\">%s</a></td>\n", $row[0],$row[$i]);
}
print("</tr>\n");
}
print("</table>\n");
mysql_num_fieldsis not compatible with PDO