anilvaghela Posted July 24, 2009 Share Posted July 24, 2009 Hi Guys n Girls... It's Friday and I am currently having a big issue. My department have finally managed to get PHP installed on a linux server woohoo!! But they are a bit stingy on what they have open and configured on the php.ini files! We have MYSQL and only PHP enabled! Now the problem that I have is I have been working on a project on my own dev server which has many extenstions open on PHP. I have a 'PDO' scripts which wont work as the driver is missing and my department said they wont open this extenstion and i need to work around this. I need help on getting the following two scripts converted into standard php and mysql scripts. The first is the 'class conn' function which connects to the db: class conn{ /*** Declare instance ***/ private static $instance = NULL; /** * the constructor is set to private so * so nobody can create a new instance using new */ private function __construct() { /*** maybe set the db name here later ***/ } /** * Return DB instance or create intitial connection * @return object (PDO) * @access public */ public static function getInstance() { if (!self::$instance) { self::$instance = new PDO("mysql:host=HOST;dbname=DB", 'USER', 'PASSWORD'); self::$instance-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$instance; } /** * Like the constructor, we make __clone private * so nobody can clone the instance */ private function __clone(){ } } /*** end of class ***/ OK thats the connection now the following statements are based in the process php file which uses the connection to run mysql scripts here is a line from there which i also need to know what i can convert it too... conn::getInstance()->beginTransaction(); $stmt = conn::getInstance()->prepare("SELECT @myorder1 := order_id FROM ref_db WHERE name_id=:name_idd__"); $stmt->bindParam(':name_idd__', $name_idd__); $stmt->execute(); That will hopefully need to change or may stay the same but the PDO function i need serious help on converting it to standard php scripting... PLEASE HELP!! Thank You!! Anil Vaghela anil@heavyvibesonline.com www.heavyvibesonline.com Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/ Share on other sites More sharing options...
dzelenika Posted July 24, 2009 Share Posted July 24, 2009 Try to use mysqli prepared statments they are very similar to PDO, and in my opinion very accurate way to work with mysql database. Because they function the same as PDO you only should replace class and function names. Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-881868 Share on other sites More sharing options...
anilvaghela Posted July 24, 2009 Author Share Posted July 24, 2009 Thanks but i should of also noted that Mysqli is also disabled and they only will allow MYSQL functions.... Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-881872 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 class conn{ /*** Declare instance ***/ private static $instance = NULL; /** * the constructor is set to private so * so nobody can create a new instance using new */ private function __construct() { /*** maybe set the db name here later ***/ } /** * Return DB instance or create intitial connection * @return object (PDO) * @access public */ public static function getInstance() { if (!self::$instance) { self::$instance = mysql_connect('HOST','USER','PASSWORD'); mysql_select_db('DB',self::$instance); } return self::$instance; } /** * Like the constructor, we make __clone private * so nobody can clone the instance */ private function __clone(){ } } /*** end of class ***/ $conn = conn::getInstance(); $sql = sprintf("SELECT @myorder1 := order_id FROM ref_db WHERE name_id = '%s'",mysql_real_escape_string($name_idd__)); mysql_query($sql,$conn) or die(mysql_error($conn)); Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-881931 Share on other sites More sharing options...
RichardRotterdam Posted July 24, 2009 Share Posted July 24, 2009 I have a 'PDO' scripts which wont work as the driver is missing and my department said they wont open this extenstion and i need to work around this. You can indeed rewrite all of it using mysql functions. However you might want to concider an alternative, what about using a written PDO class? http://www.google.com/webhp?complete=1&hl=en#complete=1&hl=en&q=pdo+php4&aq=f&oq=&aqi=g-s1&fp=5TZlSg8c0wI Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-881941 Share on other sites More sharing options...
anilvaghela Posted July 24, 2009 Author Share Posted July 24, 2009 Nice one guys I will give this ago and feed u guys back with some results..... Cheers Anil Vaghela anil@heavyvibesonline.com www.heavyvibesonline.com Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-881984 Share on other sites More sharing options...
anilvaghela Posted July 24, 2009 Author Share Posted July 24, 2009 Just one more thing about the above equation that did work for the 'conn:getinstance' query.... how would i bind the following..... $stmt = conn::getInstance()->prepare("INSERT INTO ref_db(order_id, name_id, name_ch, parent_id, level, agg, pseudo, ps_id, replevel, class, audit, tdate, user_id, checked_id, assign_id) VALUES(@myorder1 +1, :name_id, :move_node, :parent_id, :level, :agg, :pseudo, :ps_id, :replevel, :class, :audit, NOW(), :user_id, :checked_id, :assign_id)"); $stmt->bindParam(':name_id', $name_id); $stmt->bindParam(':move_node', $move_node); $stmt->bindParam(':parent_id', $parent_id); $stmt->bindParam(':level', $level); $stmt->bindParam(':agg', $agg); $stmt->bindParam(':pseudo', $pseudo); $stmt->bindParam(':ps_id', $ps_id); $stmt->bindParam(':replevel', $replevel); $stmt->bindParam(':class', $class); $stmt->bindParam(':audit', $audit); $stmt->bindParam(':user_id', $user_id); $stmt->bindParam(':checked_id', $checked_id); $stmt->bindParam(':assign_id', $assign_id); $stmt->execute(); Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-882053 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 by using the same process as above, but repeated for all those vars. i'm not gonna type it all out, but i usually use sprintf() cus i think it's cleaner. so take your SQL, and put a %s in single quotes wherever you want a value, and then add the variable as an argument to sprintf() $sql = sprintf("INSERT INTO ref_db(order_id, name_id, name_ch,....) VALUES (@myorder1 +1, '%s', '%s',...)", mysql_real_escape_string($name_id), mysql_real_escape_string($move_node), ....); mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-882057 Share on other sites More sharing options...
anilvaghela Posted July 24, 2009 Author Share Posted July 24, 2009 EXCELLENT!!!! Quote Link to comment https://forums.phpfreaks.com/topic/167248-solved-converting-php-mysql-pdo-script-into-standard-php-mysql-script/#findComment-882067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.