Search the Community
Showing results for tags 'phpsolutions'.
-
My apologies if I've placed this in the wrong section. It concerns a basic connection to n SQL database, and doing a simple count of the records. I'm learning from DAVID POWERS PHPSOLOUTIONS book. Examples in his book show connecting to the local db differently than my host wants me to connect, and I believe therin lies the issue. If I can figure out the method or problem I'm having, I'll be very thankful. I'm just connecting to a database, running one query, and counting records. The code that I altered, and I am trying to use, looks like this: <?php //Sample Database Connection Syntax for PHP and MySQL. include ('/includes/imageconn.inc.php'); include ('/includes/imagetableconn.inc.php'); mysql_select_db($dbname); # Check If Record Exists $sql = "SELECT * FROM $usertable"; $result = $conn->query($sql) or die(mysqli_error()); $numrows = $result->num_rows; ?> <html> <head> <title>PHP Test</title> </head> <body> <?php echo $numrows; ?> </body> </html> ----------------------------------------------------------------------- My imageconn.inc.php file holds a set of variables needed for the connection. I have verified it works (online, where I want), using other simple pages I made. This is the imagetableconn.inc.php file. It contains one line of code (which also works in the test file the host sent me). $conn = mysql_connect($hostname, $username, $password) or die ('Error connecting to mysql'); ------------------------------------------------------------------------- I'm pretty sure the problem lies in this line (which is from the BOOK, which I can't figure out how to modify for my online needs): $result = $conn->query($sql) or die(mysqli_error()); My error message: Fatal error: Call to a member function query() on a non-object in D:\Hosting\4641474\html\testimagedb1.php on line 12