hi im attempting to change my website from mysql to mysqli ive replace mysql with mysql on all the files and when i attempt to load site im gettting the following:
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /home/matureco/public_html/config/db_connect.php on line 6

heres code for this section

<?php
session_start();
include("config_global.php");

$conn       = mysqli_connect(DBHOST,DBUSER,DBPASS) or die(mysqli_connect_error());
$dn     = mysqli_select_db(DBNAME,$conn) or die(mysqli_connect_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']));
?>

then the file for connection details

<?php
define ("DBHOST","localhost");
define ("DBUSER","matureco_social");
define ("DBPASS","xxxxxx");
define ("DBNAME","matureco_social");


/*define ("DBUSER","root");
define ("DBPASS","");
define ("DBNAME","date_demo");*/

define ("DBPREFIX","");
define ("CHAR_SET","utf8");
define ("CACHEDIR","");
?>

if anyone can help with this be much appreicated

You have to invert the arguments: first the link to the resource, then the database name. Like this:

mysqli_select_db($conn, DBNAME);

sorted that one ty hun but now im getting the following errors

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/matureco/public_html/config/db_connect.php on line 8

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/matureco/public_html/config/db_connect.php on line 8

<?php
session_start();
include("config_global.php");

$conn       = mysqli_connect(DBHOST,DBUSER,DBPASS) or die(mysqli_connect_error());
    mysqli_select_db($conn, DBNAME);

$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']));
?>
Member Avatar for diafol

You need to supply the $conn to each mysqli_query() as the FIRST parameter. The error message told you'd only supplied one parameter. Anyway, this therefore has a knock-on effect for the outer function, mysqli_fetch_array(). It is expecting a mysqli_result object from the query, but instead has to deal with null.

Converting from mysql to mysqli is relatively easy, but you do need to consult with the manual to check the number and the order of parameters for various functions.

http://php.net/manual/en/mysqli.query.php

Procedural style
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

Shows that the function needs a mysqli object ($conn in your case) and a query string ($query). The third parameter is optional, as shown by the square brackets. It is set to MYSQLI_STORE_RESULT by default.

The manual usually has tons of examples on each function / method, so it should be your first port of call.

As said, the manual (found on the PHP web site) will help a LOT in dealing with this. That's how I learned.

One small question , you are changing your code why changing to mysqli where there is not the option of real prepared statements and not to PDO where there are (and more over has implementations that make it easier to use even than mysql functions) ?

Comment : I strongly believe that the PDO team has done a great job even if they gave PHP programmers options that are week but easy to understand as bindParam , but from that they even created a tool that can be used in many ways , it ain't paradigm agnostic as Lerdorf keep saying about PHP , it is usage agnostic. It is not wondering why PDO core is making its way in other languages as well. A very sincere sentense to those programmers is just “thank you”. Of course PDO has its week points (not opposite to mysqli , mysqli hasn't those , because it don't support them). PDO build in an era that there where not real prepared statements in MySql, now there are. I have shown a way of overlapping that factor in one tutorial.

Member Avatar for diafol

Also you may want to do the trimming on insert, rather than select.

i dont have any clue with PDO hun x

hi i have put $conn in the following

$row = $result->fetch_array($conn, mysqli_query("select * from settings where id = '1' "));

and where every mysqli_query is and im now getting:
Parse error: syntax error, unexpected ',' in /home/matureco/public_html/config/db_connect.php on line 196

is this correct and also do i have to put it on every php that as mysqli_query hun

You are putting the $conn in wrong place... Please take a look at its syntax here. Tldr, put the $conn as part of mysqli_query parameter, not in fetch_array...

Member Avatar for diafol

This is why I said check the manual. You will see that fetch varieties do not have a mysqli object param. Confused though. Looks like you are mixing oop and procedural approaches.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.