...

View Full Version : mysqli query not working



sitNsmile
03-25-2010, 04:26 PM
Okay trying to use mysqli this time, but I cant seem to get the query working through the class.



$SC_query = $arcade_db->query("SELECT * FROM site_config");
$SC_row = mysql_fetch_array($SC_query);




public function query($query){
$this->result = mysql_query($query,$this->mysql);
return $this;
}


I don't notice anything wrong so far.

Thanks

sitNsmile
03-25-2010, 04:49 PM
Decided to do it this way.



public function query($query) {

$result = mysql_query($query, $this->mysql);

if (!($result)) {
ob_end_clean();
die("SQL Error: ".mysql_error($this->mysql)."<br /> Query: $query<br />");
}
return $result;
}


Still dont know yet what I was doing wrong above, its probably something small and will notice it soon.

djdubuque
03-25-2010, 04:54 PM
Okay trying to use mysqli this time, but I cant seem to get the query working through the class.



$SC_query = $arcade_db->query("SELECT * FROM site_config");
$SC_row = mysql_fetch_array($SC_query);


public function query($query){
$this->result = mysql_query($query,$this->mysql);
return $this;
}
I don't notice anything wrong so far.

Thanks

You said you where using mysqli shouldn't your query be;


mysqli_query
mysqli_fetch_array

mic2100
03-25-2010, 05:06 PM
You said you where using mysqli shouldn't your query be;


mysqli_query
mysqli_fetch_array


That wot i was just thinking :P

sitNsmile
03-25-2010, 05:08 PM
That wot i was just thinking :P


yeah I've actually tired that after you mentioned it. But don't think that had much to do with it, or maybe I am confused with classes and what mysql or mysqli differences.

djdubuque
03-25-2010, 05:16 PM
Not sure about your full code but I did find this, does this make sense?


<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

$query = "SELECT Name, SurfaceArea from Country ORDER BY Name LIMIT 5";

if ($result = mysqli_query($link, $query)) {

/* Get field information for column 'SurfaceArea' */
$finfo = mysqli_fetch_field_direct($result, 1);

printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n", $finfo->type);

mysqli_free_result($result);
}

/* close connection */
mysqli_close($link);
?>

Dormilich
03-25-2010, 05:43 PM
Okay trying to use mysqli this time, but I cant seem to get the query working through the class.



public function query($query){
$this->result = mysql_query($query,$this->mysql);
return $this;
}


as already mentioned, if you start with mysqli, you cannot use mysql_* functions (kinda obvious, ainít it?).

if you like object oriented style, why not using the OOP style of MySQLi?


$db = new MySQLi($host, $user, $pass);
$db->query(Ö);

sitNsmile
03-25-2010, 08:48 PM
as already mentioned, if you start with mysqli, you cannot use mysql_* functions (kinda obvious, ainít it?).

if you like object oriented style, why not using the OOP style of MySQLi?


$db = new MySQLi($host, $user, $pass);
$db->query(Ö);

yes that is already in process. I thought I was already doing that?

sitNsmile
03-25-2010, 08:49 PM
Not sure about your full code but I did find this, does this make sense?


<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

$query = "SELECT Name, SurfaceArea from Country ORDER BY Name LIMIT 5";

if ($result = mysqli_query($link, $query)) {

/* Get field information for column 'SurfaceArea' */
$finfo = mysqli_fetch_field_direct($result, 1);

printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n", $finfo->type);

mysqli_free_result($result);
}

/* close connection */
mysqli_close($link);
?>

Makes sense, yes. But I am trying to build the mysql class to allow me to run multi database (2 database) on 1 site.

Dormilich
03-25-2010, 09:01 PM
I thought I was already doing that?

didnít look like that.


Makes sense, yes. But I am trying to build the mysql class to allow me to run multi database (2 database) on 1 site.

something like that?

$db1 = new MySQLi(Ö);
$db2 = new MySQLi(Ö);

sitNsmile
03-25-2010, 09:04 PM
didnít look like that.



something like that?

$db1 = new MySQLi(Ö);
$db2 = new MySQLi(Ö);

Yeah I've tried that, and yet it always plays the database added last as the default. I tried different ways to only fetch queries on specific databases, but doesn't listen to it. Still looking into defining that, have code or resource that could speed that up, would be great, I'll keep testing.

Dormilich
03-25-2010, 09:18 PM
I usually use PDO and only one DB, so I don’t know for sure.

Fou-Lu
03-25-2010, 09:24 PM
Treat mysqli as an object and you can 'jail' it to its particluar instance. Otherwise, all mysql and mysqli procedural methods include a reference for a $link_id or $resouce_id. This refers to you're connection itself, and if not present it will use the last one available.


$db1 = new MySQLi(...);
$db2 = new MySQLi(...);

$db1->query('SELECT ....'); // Uses the $db1 connection
mysqli_query('SELECT ....'); // ! uses $db2 connection
mysqli_query($db1, 'SELECT ....'); // Uses $db1 connection


That make sense?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum