note 115718 added to mysqli.query

From: Date: Fri, 12 Sep 2014 11:39:24 +0000
Subject: note 115718 added to mysqli.query
Groups: php.notes 
Request: Send a blank email to php-notes+get-200429@lists.php.net to get a copy of this message
Hi, i created function that add a new table using array , i work with it on my projects ... <?PHP /* this function was learned from PHP.net */ function array_keys_exist(&$key,array &$array){ $keys = split("\|",$key); foreach($keys as $key_s){ if(array_key_exists($key_s, $array)) return true; } return false; } /*and this is my function */ array_create_table(array &$array){ if(is_array($array)){ $key = "table|rows|values"; $info = ""; if(array_keys_exist($key,$array)){ if(is_array($array["rows"]) and is_array($array["values"]) ){ if(count($array["rows"]) == count($array["values"])) { for($i=0; $i<=count($array["rows"]); $i++){ $info = $info." ".$array["rows"][$i]." ".$array["values"][$i]." NOT NULL "; if($i < count($array["rows"])-1 ) $info = $info.","; } $query = "CREATE TABLE ".$this->private_tables_name.$array["table"]." "; $query .= "( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ".$info." )"; return $query; } } }else return "Error"; } } /* the use is simple */ $database = new database(); // connection to database i used mysqli ... $array = array("table"=>"MRO", "rows"=>array("name","username") , "values" => array("VARCHAR (50) "," VARCHAR (50) ") ); $query = array_create_table($array); // convert and create the query ... if($database->query($query)) echo "Work"; else echo "Error"; // result : work ?> ---- Server IP: 113.20.13.217 Probable Submitter: 41.111.112.134 ---- Manual Page -- http://php.net/manual/en/mysqli.query.php Edit -- https://master.php.net/note/edit/115718 Del: integrated -- https://master.php.net/note/delete/115718/integrated Del: useless -- https://master.php.net/note/delete/115718/useless Del: bad code -- https://master.php.net/note/delete/115718/bad+code Del: spam -- https://master.php.net/note/delete/115718/spam Del: non-english -- https://master.php.net/note/delete/115718/non-english Del: in docs -- https://master.php.net/note/delete/115718/in+docs Del: other reasons-- https://master.php.net/note/delete/115718 Reject -- https://master.php.net/note/reject/115718 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200429) next »