0

Hi im attempting to change from mysql to mysqli and ive used a editor that changes it all and im getting the following error after changing all files Fatal error: Call to a member function query() on a non-object in /home/matureco/public_html/config/db_connect.php on line 7

heres the piece of coding for that

    $conn       = new mysqli(DBHOST,DBUSER,DBPASS) or die($mysqli->error);

$row        = mysqli_fetch_array($mysqli->query("select * from settings where id = '1' "));
$site_name  = trim(stripslashes($row['site_name']));
$email      = trim($row['email']);
$keyword    = trim(stripslashes($row['keyword']));
$description= trim(stripslashes($row['description']));
$logo       = trim($row['logo']);
$copyright  = trim(stripslashes($row['copyright']));

$favicon    = trim($row['favicon']);
$paypal_email   = trim($row['paypal_email']);

can anyone tell me what ive missed

much appreciated ty jan x

  • 1
    `mysqli(DBHOST,DBUSER,DBPASS)` what's missing here? I'll make you think about it for a bit. edit: oh and the wrong variable. http://php.net/manual/en/function.mysqli-connect.php --- http://php.net/manual/en/mysqli.error.php – Funk Forty Niner Nov 19 '15 at 18:46

2 Answers2

1

$mysqli is not an object in your code. $conn is the object you declared.

Your code should show this:

$row        = mysqli_fetch_array($conn->query("select * from settings where id = '1' "));

Also, you are missing a parameter in the object declaration to set the database itself:

Correct Syntax:

$obj = new mysqli("my_host", "my_user", "my_password", "my_db");
skrilled
  • 5,350
  • 2
  • 26
  • 48
0

$mysqli->query("select * from settings where id = '1' ")); should be

$conn->query("select * from settings where id = '1' "));

since you are going to use oop approach. You should change your code to that way. this is my suggestion

$result       = $conn->query("select * from settings where id = '1' ");
$row = $result->fetch_object()
$site_name  = trim(stripslashes($row->site_name));
$email      = trim($row->email);
$keyword    = trim(stripslashes($row->keyword));
$description= trim(stripslashes($row->description));
$logo       = trim($row->logo);
$copyright  = trim(stripslashes($row->copyright));

$favicon    = trim($row->favicon);
$paypal_email   = trim($row->paypal_email);
Burak Karasoy
  • 1,682
  • 2
  • 21
  • 33
  • ive tried the code above Burak but im just getting further errors – Jan Robinson Murby Nov 19 '15 at 19:09
  • because i forgot to change thing what i told you to do now i edited it :) i hope it works control your variables syntax email,logo,keyword i might have made mistake while writing them.I am suspicious about trim and stripslashed methods if you get error you had better check these. – Burak Karasoy Nov 19 '15 at 19:15
  • ive resolved that line now im getting a error on line 67 fatal error: call to a member function query() on a non-object in /home/matureco/public_html/config/db_connect.php on line 67 `code`if(! function_exists(unReadMsgCount) ) { function unReadMsgCount($id) { return $conn->query("select * from messages where rece_id='".$id."' and readflage = 0 and status=1")->num_rows; } }`code` – Jan Robinson Murby Nov 19 '15 at 19:29
  • it is not easy to solve a code which was written like that.try this after you assigned your conn. if you get error it means your connection is not correct.Check your hostname,id,databasename etc.if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }http://www.w3schools.com/php/func_mysqli_connect.asp – Burak Karasoy Nov 19 '15 at 19:39
  • Ive replaced my connection file with the one in w3c @burak Karasoy and im getting Warning: mysqli_connect(): (HY000/1044): Access denied for user 'matureco_social'@'localhost' to database 'my_db' in /home/matureco/public_html/config/config_global.php on line 3 Failed to connect to MySQLI: Access denied for user 'matureco_social'@'localhost' to database 'my_db' – Jan Robinson Murby Nov 19 '15 at 19:53
  • Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/matureco/public_html/config/db_connect.php on line 5 Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/matureco/public_html/config/db_connect.php on line 5 Warning: mysqli::query(): Couldn't fetch mysqli in /home/matureco/public_html/config/db_connect.php on line 7 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/matureco/public_html/config/db_connect.php on line 7 – Jan Robinson Murby Nov 19 '15 at 19:54
  • new mysqli(DBHOST,DBUSER,DBPASS,????) where did you assign your database name. – Burak Karasoy Nov 19 '15 at 19:58
  • i since added to here hun $conn = new mysqli(DBHOST,DBUSER,DBPASS,DBNAME) or die($mysqli->error); but im still getting same errors – Jan Robinson Murby Nov 19 '15 at 20:20