note 105418 added to ref.pdo-dblib
| From: | artistan at gmail dot com | Date: | Tue, 16 Aug 2011 14:30:34 +0000 |
| Subject: | note 105418 added to ref.pdo-dblib | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182511@lists.php.net to get a copy of this message | ||
thanks to tris+php note....
and this note on unique identifier needing to cast to varchar(36)..
http://blog.dynom.nl/archives/What-do-you-get-when-you-mix;-MSSQL,-PDO-and-uniqueidentifier_20100608_57.html
<?
class mssql {
private static $statement=null;
private static $typemap=array(
'ntext' => 'text',
'bigint' => 'real',
'decimal' => 'real',
'float' => 'real',
'numeric' => 'real',
"uniqueidentifier" => 'varchar(36)'
);
public static function all_fields($table,&$db,$query='') {
try{
if(!$query) {
$query="SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_NAME=?";
}
self::$statement=$db->prepare($query);
self::$statement->execute(array($table));
$fields=array();
$need_cast=false;
while($field=self::$statement->fetch(PDO::FETCH_ASSOC)) {
//var_dump($field);
$field_quoted=self::quote_field_name($field['COLUMN_NAME']);
if(isset(self::$typemap[$field['DATA_TYPE']])) {
$fields[]='CAST('.$field_quoted.' AS
'.self::$typemap[$field['DATA_TYPE']].') AS '.$field_quoted;
$need_cast=true;
} else $fields[]=$field_quoted;
}
} catch (PDOException $e) {
echo "Failed to get DB fields: " . $e->getMessage() . "\n";
exit;
}
return ($need_cast) ? implode(', ',$fields) : '*';
}
public static function quote_field_name($field) {
$pos=strpos($field,' ');
return ($pos===false) ? $field : '['.$field.']';
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 67.138.129.34
----
Manual Page -- http://www.php.net/manual/en/ref.pdo-dblib.php
Edit -- https://master.php.net/note/edit/105418
Del: integrated -- https://master.php.net/note/delete/105418/integrated
Del: useless -- https://master.php.net/note/delete/105418/useless
Del: bad code -- https://master.php.net/note/delete/105418/bad+code
Del: spam -- https://master.php.net/note/delete/105418/spam
Del: non-english -- https://master.php.net/note/delete/105418/non-english
Del: in docs -- https://master.php.net/note/delete/105418/in+docs
Del: other reasons-- https://master.php.net/note/delete/105418
Reject -- https://master.php.net/note/reject/105418
Search -- https://master.php.net/manage/user-notes.php