Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-27-2013, 05:25 PM   PM User | #16
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
We also use this for what is shown above:


var $function = array(
'connect' => 'mysql_connect',
'select_db' => 'mysql_select_db',
'query' => 'mysql_query',
'num_rows' => 'mysql_num_rows',
'close' => 'mysql_close',
'fetch_array' => 'mysql_fetch_array',
'escape' => 'mysql_real_escape_string'
);
fondy98 is offline   Reply With Quote
Old 02-27-2013, 05:34 PM   PM User | #17
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,661
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Resource id #x indicates that you've successfully acquired a resource in PHP. As pointed out, that means that the SQL did return a result. Use a command line client or something like phpMyAdmin to execute queries directly so see the results.
In PHP world, you now have a resource in which you can operate on. The resource by itself is useless; you cannot print out a resource and expect anything meaningful off of it. You need to issue a fetch command to it to actually retrieve the data. Since you are using a custom class, we cannot provide you information on the fetching itself. Using just mysqli library directly, you'd have:
PHP Code:
$sQry =  "SELECT parent, MAX(`timestamp`) AS maxTimestamp FROM " PREFIX "replies WHERE type = 'ticket' GROUP BY parent";
if (
$qry $mysqliObj->query($sQry))
{
    while (
$aRecord $qry->fetch_assoc())
    {
        
printf("Max timestamp for parent %s is %s" PHP_EOL$aRecord['parent'], $aRecord['maxTimestamp']);
    }
    
$qry->free();

Edit:
Actually, with this list above you may be able to call the method fetch_array on the db object. That's a bad way of injecting functionality into it though.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php

Last edited by Fou-Lu; 02-27-2013 at 05:37 PM..
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 07:00 PM   PM User | #18
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
This is some of the code:

$replied = $site->db->query("SELECT parent, MAX(`timestamp`) AS maxTimestamp FROM " . PREFIX . "replies WHERE type = 'ticket' GROUP BY parent");
if ($qry = $mysqliObj->query($sQry))
{
while ($aRecord = $qry->fetch_assoc())
{
printf("Max timestamp for parent %s is %s" . PHP_EOL, $aRecord['parent'], $aRecord['maxTimestamp']);
}
$qry->free();
}

Last edited by fondy98; 02-27-2013 at 07:06 PM.. Reason: I still cannot get it to budge
fondy98 is offline   Reply With Quote
Old 02-27-2013, 07:02 PM   PM User | #19
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,661
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You can't just copy and paste the mysqli usage. That was done as an example. You need to figure out how to make it work with your custom $site->db object.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
fondy98 (02-27-2013)
Old 02-27-2013, 07:05 PM   PM User | #20
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
Oops, I did try and replace most of it, but still no go. That one above was accidentally the original mysqli usage. By the way, I don't think that mysqli will work as we are only on mySQL
fondy98 is offline   Reply With Quote
Old 02-27-2013, 07:08 PM   PM User | #21
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
$replied = $site->db->query("SELECT parent, MAX(`timestamp`) AS maxTimestamp FROM " . PREFIX . "replies WHERE type = 'ticket' GROUP BY parent");
if ($replied = $site->db->query($sQry))
{
while ($ticket = $replied->fetch_assoc())
{
printf("Max timestamp for parent %s is %s" . PHP_EOL, $ticket['parent'], $ticket['maxTimestamp']);
}
$replied->free();
}

I tried this as well
fondy98 is offline   Reply With Quote
Old 02-27-2013, 07:09 PM   PM User | #22
fondy98
New Coder

 
Join Date: Feb 2013
Posts: 15
Thanks: 9
Thanked 0 Times in 0 Posts
fondy98 is an unknown quantity at this point
$replied = $site->db->query("SELECT parent, MAX(`timestamp`) AS maxTimestamp FROM " . PREFIX . "replies WHERE type = 'ticket' GROUP BY parent");
if ($replied = $site->db->query($sQry))
{
while ($replies = $replied->fetch_assoc())
{
printf("Max timestamp for parent %s is %s" . PHP_EOL, $replies['parent'], $replies['maxTimestamp']);
}
$replied->free();
}

ANd I tried this too
fondy98 is offline   Reply With Quote
Old 02-27-2013, 07:35 PM   PM User | #23
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,661
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
MySQLi is the replacement for MySQL. Since the mysql library will disappear in the future, the mysqli is there to replace it.
Still isn't correct. $sQry doesn't exist anywhere here, so $replied will be set without a resource.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
fondy98 (02-27-2013)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00 AM.


Advertisement
Log in to turn off these ads.