View Single Post
  #3  
Old 01-13-2015, 10:34 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 114,962
Kyttias is on a distinguished road
Default

If you like, I've been slowly working on this guide.

Or, in short, for just your question:

Database SQL Statements
You’ll need to have access to the registry first, in whatever function you're dealing with, of course.
PHP Code:
$mysidia Registry::get("mysidia"); 
Counting Rows
Count how many rows match a specific query:
PHP Code:
$mysidia->db->select("Table", array("Column"), "Row='{$somevalue}' and Row >= {$somevalue}")->rowCount(); 
Compare to:
Code:
SELECT COUNT(Row) FROM Column WHERE Row='$somevalue' and Row >= {$somevalue};
Where Data
Fetching an exact value in a specified column:
PHP Code:
$mysidia->db->select("Table", array("Column"), "Row = '$somevalue'")->fetchColumn(); 
Compare to:
Code:
SELECT Column FROM Table WHERE Row='$somevalue';
Fetching Row Data as an Object
Example:
PHP Code:
$pet $mysidia->db->select("owned_adoptables", array(), "owner='{$mysidia->user->username}' ORDER BY RAND() LIMIT 1")->fetchObject(); 
You could now use {$pet->name} and {$pet->currentlevel}, etc. (This example chooses a random pet owned by the user.)
Creating a New Row of Data
Example:
PHP Code:
$mysidia->db->insert("Table", array("Column" => $somevalue"Column" => 'somevalue')); 
Compare to:
Code:
INSERT INTO table_name (Column1, Column2, Column3) VALUES ($somevalue1, $somevalue2, $somevalue3);
Updating Data
PHP Code:
$mysidia->db->update("Table", array("Column" => '$somevalue'), "Row = '$somevalue'"); 
Compare to:
Code:
UPDATE Table SET Column='$somevalue' WHERE Row='$somevalue';
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote