Skip to content

Instantly share code, notes, and snippets.

@ozh
Last active August 20, 2017 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozh/d60fcc8e22103ca1b35e7c799f5df02b to your computer and use it in GitHub Desktop.
Save ozh/d60fcc8e22103ca1b35e7c799f5df02b to your computer and use it in GitHub Desktop.
Aura.sql fetch* methods and their outputs
<?php
/**
* Table is :
* +-----------+-------------+--------------+
* | option_id | option_name | option_value |
* +-----------+-------------+--------------+
* | 1 | version | 1.7.2 |
* | 2 | db_version | 1337 |
* | 3 | next_id | 69 |
* +-----------+-------------+--------------+
*/
$table = YOURLS_DB_TABLE_OPTIONS;
$sql = "SELECT option_name, option_value FROM $table WHERE 1=1";
echo "fetchAll\n";
$options = $ydb->fetchAll($sql);
var_dump($options);
/*
array (size=3)
0 =>
array (size=2)
'option_name' => string 'version' (length=7)
'option_value' => string '1.7.1' (length=5)
1 =>
array (size=2)
'option_name' => string 'db_version' (length=10)
'option_value' => string '482' (length=3)
2 =>
array (size=2)
'option_name' => string 'next_id' (length=7)
'option_value' => string '32' (length=2)
*/
echo "fetchAssoc\n";
$options = $ydb->fetchAssoc($sql);
var_dump($options);
/*
array (size=3)
'version' =>
array (size=2)
'option_name' => string 'version' (length=7)
'option_value' => string '1.7.1' (length=5)
'db_version' =>
array (size=2)
'option_name' => string 'db_version' (length=10)
'option_value' => string '482' (length=3)
'next_id' =>
array (size=2)
'option_name' => string 'next_id' (length=7)
'option_value' => string '32' (length=2)
*/
echo "fetchGroup\n";
$options = $ydb->fetchGroup($sql);
var_dump($options);
/*
array (size=3)
'version' =>
array (size=1)
0 => string '1.7.1' (length=5)
'db_version' =>
array (size=1)
0 => string '482' (length=3)
'next_id' =>
array (size=1)
0 => string '32' (length=2)
*/
echo "fetchObject\n";
$options = $ydb->fetchObject($sql);
var_dump($options);
/*
object(stdClass)[292]
public 'option_name' => string 'version' (length=7)
public 'option_value' => string '1.7.1' (length=5)
*/
echo "fetchObjects\n";
$options = $ydb->fetchObjects($sql);
var_dump($options);
/*
array (size=3)
0 =>
object(stdClass)[293]
public 'option_name' => string 'version' (length=7)
public 'option_value' => string '1.7.1' (length=5)
1 =>
object(stdClass)[294]
public 'option_name' => string 'db_version' (length=10)
public 'option_value' => string '482' (length=3)
2 =>
object(stdClass)[295]
public 'option_name' => string 'next_id' (length=7)
public 'option_value' => string '32' (length=2)
*/
echo "fetchOne\n";
$options = $ydb->fetchOne($sql);
var_dump($options);
/*
array (size=2)
'option_name' => string 'version' (length=7)
'option_value' => string '1.7.1' (length=5)
*/
echo "fetchPairs\n";
$options = $ydb->fetchPairs($sql);
var_dump($options);
/*
array (size=3)
'version' => string '1.7.1' (length=5)
'db_version' => string '482' (length=3)
'next_id' => string '32' (length=2)
*/
echo "fetchValue\n";
$options = $ydb->fetchValue($sql);
var_dump($options);
/*
string 'version' (length=7)
*/
echo "fetchCol\n";
$options = $ydb->fetchCol($sql);
var_dump($options);
/*
array (size=3)
0 => string 'version' (length=7)
1 => string 'db_version' (length=10)
2 => string 'next_id' (length=7)
*/
echo "fetchAffected\n";
$options = $ydb->fetchAffected($sql);
var_dump($options);
/*
int 3
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment