-1

i need to convert my project from MySQL to MySQL I, i do fetch object in MySQL and its working but in MySQL I its not working

this code in MySQL (its working)

$sqlSelectSe = mysql_query("SELECT * FROM config");
 $FetchSe = mysql_fetch_object($sqlSelectSe);

  define("s_name",$FetchSe->s_name);
  define("s_url",$FetchSe->s_url);
  define("s_email",$FetchSe->s_email);

And This in MySQL I (NOT WORK)

   $sqlSelectSe = $mysqli->query("SELECT * FROM config");
   $FetchSe = mysql_fetch_object($sqlSelectSe);

   define("s_name",$FetchSe->s_name);
   define("s_url",$FetchSe->s_url);
   define("s_email",$FetchSe->s_email);
  • 2
    You're mixing `mysql_` and `mysqli_` – kero Feb 11 '16 at 22:49
  • i am new in learn in mysqli – mutaz Ghosheh Feb 11 '16 at 22:51
  • 1
    `$FetchSe = mysqli_fetch_object( $conn, $sqlSelectSe );` ~ you need to suply the connection object and use `mysqli_*` for function calls – Professor Abronsius Feb 11 '16 at 22:55
  • Possible duplicate of [Can I mix MySQL APIs in PHP?](http://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – Qirel Feb 11 '16 at 22:55
  • @RamRaider .. $conn from where.!! from config.php? – mutaz Ghosheh Feb 11 '16 at 23:00
  • presumably @mutaz - wherever you initially define your database connections - it may not be called $conn – Professor Abronsius Feb 11 '16 at 23:06
  • thank you @RamRaider . i'am try it but it's not work $FetchSe = mysqli_fetch_object( $Dbconnect, $sqlSelectSe ); – mutaz Ghosheh Feb 11 '16 at 23:09
  • Where are you defining $mysqli? Does it look something like this: `$mysqli = new mysqli("host", "user", "password", "db");`? –  Feb 11 '16 at 23:20
  • thank you @mark.hch yes but i do it in array $Db = array ( "hostname"=>"localhost", "dbname"=>"prstitodb", "dbuser"=>"root", "dbpass"=>"", ); $Dbconnect = mysqli_connect($Db['hostname'],$Db['dbuser'],$Db['dbpass']) or die(mysqli_error()); $DbSelect = mysqli_select_db($Dbconnect,$Db['dbname']) or die(mysqli_error($Dbconnect)); And its work – mutaz Ghosheh Feb 11 '16 at 23:26
  • @mutazGhosheh ~ you need to use the connection object in the initial query too. Use error reporting when you are developing code and refer to your log files ( php log file specifically ) – Professor Abronsius Feb 11 '16 at 23:26
  • thank you @RamRaider i well use it now but its still not working $conn = new mysqli("localhost", "root", "", "prstitodb"); $sqlSelectSe = $mysqli->query("SELECT * FROM config"); $FetchSe = mysqli_fetch_object($conn, $sqlSelectSe ); – mutaz Ghosheh Feb 11 '16 at 23:32
  • so close with your last comment - check @RamRaider 's answer. In your comment it would be `$conn->query` instead of `$mysqli->query` since you assigned your mysqli object to the `$conn` variable. –  Feb 12 '16 at 00:03

2 Answers2

0

the connection style I use for mysqli connections is as follows; hopefully you should be able to get your connection working if you do likewise. Try not to mix up procedural and OO style code ~ it will probably work but is bad practise and leads to bad habits.

$dbhost =   'localhost';
$dbuser =   'root'; 
$dbpwd  =   'xxx'; 
$dbname =   'xxx';
$conn   =   new mysqli( $dbhost, $dbuser, $dbpwd, $dbname );

I then prefer to use OO style notation in keeping with the initial connection, so a query to select records:

$sql='select * from users';
$results=$conn->query( $sql );
if( $results ){
    while( $rs=$results->fetch_object() ) echo $rs->username;/* etc */
}
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
0

thank you man @RumRaider and i solve it from another way

$conn = mysqli_connect("localhost", "root", "", "prstitodb");
$sql="SELECT * FROM config";
if ($result=mysqli_query($conn,$sql)){
$FetchSe = mysqli_fetch_object($result);