-
Posts
827 -
Joined
-
Last visited
-
Days Won
9
Everything posted by fastsol
-
You're missing a closing " at the end of the first line. SImply viewing the code after you posted it woudl have shwon you that pretty easily
-
how to handle errors in mysqli prepared statements efficiently
fastsol replied to ajoo's topic in PHP Coding Help
Use a db wrapper class that has the functionality you want built in to it. This way every time you run a query it goes through the class and will automatically do the error checking. -
Ahh yes, I ended up putting it at the bottom of run() with all the other var resets cause I do a _bind check in the run to determine what execute method to use. Either way it worked. It's been roughly 5 months since I have done much coding so I forgot how I really built that wrapper. Thanks for the help!
-
I have a DB wrapper class that I built, it's not fancy and likely not "real" good I would suspect as classes are not my strong suit. I ran into a situation today that I didn't know could happen cause I probably don't fully understand how pdo works or maybe it's my db class creating this issue. I called a function and tried to run a prepare() using bindParam()s, then later in the same function I tried to run a prepare with just using the execute(array('blah')) type format. For some reason (this is my issue I'm asking about) even though I used different php vars to store the retrieved db info, the 2nd query failed cause it was still holding the binded values from the first query. Once I switched the first query to the same execute(array('blah')) format both queries worked just fine. Now granted I can certainly leave the queries written like they are now and all will be fine, but I am curious as to how to fix such a situation. I don't know if the issue lies in my db class or maybe pdo just doesn't work this way. Here is the code for the db class (be kind, it works how I want other than this snag). class DB { private static $_instance = NULL; private $_pdo, $_query, $_results, $_count = 0, $_error = FALSE, $_sql, $_bind = FALSE, $_error_reason, $_params, $_found_rows, $_success, $_query_type; private function __construct() { try { $db_options = array( PDO::ATTR_EMULATE_PREPARES => false, // important! use actual prepared statements (default: emulate prepared statements) PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // throw exceptions on errors (default: stay silent) PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC // fetch associative arrays (default: mixed arrays) ); $this->_pdo = new PDO('mysql:host='.Config::get('site_host').';dbname='.Config::get('database_name'), Config::get('mysql_username'), Config::get('mysql_password'), $db_options); } catch (PDOException $e) { header('Location: maintenance.php'); exit(); } } public static function getInstance() { if(!isset(self::$_instance)) { self::$_instance = new DB(); } return self::$_instance; } public function bind($param, $value, $type = null) { switch ($type) { case 'INT': $bind = PDO::PARAM_INT; break; case 'BOOL': $bind = PDO::PARAM_BOOL; break; case 'NULL': $bind = PDO::PARAM_NULL; break; default: $bind = PDO::PARAM_STR; } $this->_query->bindValue($param, $value, $bind); $this->_bind = TRUE; } public function query($sql) { $this->_bind = FALSE; $this->_sql = $sql; $this->_query_type = 'query'; $this->run(); return $this; } public function prepare($sql) { $this->_sql = $sql; $this->_query_type = 'execute'; $this->_query = $this->_pdo->prepare($sql); //print_r($this->_query); return $this; } public function execute($arg = array()) { $this->_params = $arg; $this->run(); return $this; } private function run() { try { $this->_count = ''; if($this->_query_type == 'query') { $this->_query = $this->_pdo->query($this->_sql); } elseif($this->_bind !== FALSE) { $this->_query->execute(); } else { $this->_query->execute($this->_params); } $this->_count = $this->_query->rowCount(); if(strpos($this->_sql, 'SQL_CALC_FOUND_ROWS') !== FALSE) { $this->_found_rows = $this->_pdo->query('SELECT FOUND_ROWS();')->fetch(PDO::FETCH_COLUMN); } else{ $this->_found_rows = ''; } $this->_query_type = ''; $this->_success = TRUE; $this->_error = FALSE; $this->_error_reason = ''; return TRUE; } catch(PDOException $e) { $this->_error = TRUE; $this->_error_reason = $e; $this->_success = FALSE; return FALSE; } } public function foundRows() { return $this->_found_rows; } public function fetch() { return $this->_query->fetch(); } public function fetchAll() { return $this->_query->fetchAll(); } public function fetchColumn() { return $this->_query->fetchColumn(); } public function fetchAllColumns() { return $this->_query->fetchAll(PDO::FETCH_COLUMN); } // $item allows you to select a specific item from the array returned. // $index allows you to select a specific array key from the array returned. public function error() { return $this->_error; } public function success() { return $this->_success; } public function rowCount() { return $this->_count; } public function printSql() { return $this->_sql; } public function errorReason() { return $this->_error_reason; } public function debugDumpParams() { return $this->_query->debugDumpParams(); } public function lastInsertId() { return $this->_pdo->lastInsertId(); } } Here is the first query that oiginally had the bind(). I left the bind() code in there for future reference but is currently commented out. When I did try the bind() I did not have anything in the execute(), just to be clear. $check_quotes = DB::getInstance()->prepare("SELECT `".QUOTE_REQUESTS."`.*, `".QUOTE_RESPONSES."`.`id` AS `quote_id`, `".QUOTE_RESPONSES."`.`code`, `".QUOTE_RESPONSES."`.`quote_active` FROM `".QUOTE_REQUESTS."` LEFT JOIN `".QUOTE_RESPONSES."` ON `".QUOTE_RESPONSES."`.`request_id` = `".QUOTE_REQUESTS."`.`id` WHERE `".QUOTE_REQUESTS."`.`email` = :e AND `".QUOTE_REQUESTS."`.`vehicle` = :v OR `".QUOTE_REQUESTS."`.`name` = :n AND `".QUOTE_REQUESTS."`.`vehicle` = :v2"); /*$check_quotes->bind(':e', $emaile); $check_quotes->bind(':v', $full_car); $check_quotes->bind(':n', $full_name); $check_quotes->bind(':v2', $full_car);*/ $check_quotes->execute(array($emaile, $full_car, $full_name, $full_car)); $quotes = $check_quotes->fetchAll(); Here is the 2nd query further down the function. $set = $db->prepare("INSERT INTO `".QUOTE_REQUESTS."` SET `request_active` = 1, `name` = ?, `vehicle` = ?, `options` = ?, `units` = ?, `phone` = ?, `email` = ?, `city` = ?, `key_type`= ?, `key_id` = $key_id, `trans`= ?, `date_sent`= $now, `cookie_code` = ?, `send_sms` = $sms, `comments` = ?, `email_list` = $email_list, `ad_campaign` = ?, `engine` = ?, `gift_name` = ?, `gift_phone` = ?, `gift_email` = ?, `gift_date` = ?"); $set->execute(array($full_name, $full_car, $the_options, $units, $phone, $emaile, $city, $key_type, $trans, $cookie_code, $comments, $ad_campaign, $engine, $gift_name, $gift_phone, $gift_email, $gift_date_formatted));
-
Thank you so very much. I was trying to mess with the lookbehind last night but couldn't get the right thing to happen. You're awesome!
-
I think I'm getting closer. Using this code foreach($rows as $row) { $parts = preg_split('/[0-9]{4}\s/', $row['vehicle']); //print_r($parts); //preg_match_all('/(.*[0-9]{4})\s+(.*)/', $row['vehicle'],$parts); print_r($parts); /*echo 'up to and including the 4 digit number - ' . $parts[1][0] . '<br>'; echo 'after the 4 digit number - ' . $parts[2][0]; */ echo '<br><br>'; } I now get the years on the rows that don't have any words after the year in the string, but still no years in the ones with words after the year. Array ( [0] => Chrysler 300 (standard key) 2005 ) Array ( [0] => Ford Fusion 2012 ) Array ( [0] => Nissan Quest [1] => PTS ) // No year here Array ( [0] => Jeep Liberty 2005 ) Array ( [0] => Pontiac Sunfire 2005 ) Array ( [0] => Subaru Legacy 2014 ) Array ( [0] => Buick Lucerne 2006 ) Array ( [0] => Saturn Ion 2004 ) Array ( [0] => Ford Escape (standard key) 2010 ) Array ( [0] => Chevrolet Cruze (flip key) 2014 ) Array ( [0] => Acura MDX 2013 ) Array ( [0] => Subaru Impreza 2015 ) Array ( [0] => Ford Focus (standard key) 2007 ) Array ( [0] => Toyota Corolla 2009 ) Array ( [0] => Nissan Murano 2004 ) Array ( [0] => Honda CR-V 2003 ) Array ( [0] => Toyota Yaris 2007 ) Array ( [0] => Chevrolet Silverado (standard key) 2004 ) Array ( [0] => Subaru Legacy [1] => Manual Trans ) // No year here Array ( [0] => Volkswagen Routan 2010 ) Array ( [0] => Ford Crown Vic 2008 ) Array ( [0] => Infiniti M35 / M45 [1] => PTS ) // No year here Array ( [0] => Toyota Highlander [1] => PTS ) // No year here Array ( [0] => Ford Edge (standard key) 2012 ) Array ( [0] => Nissan Titan 2007 ) Array ( [0] => Toyota RAV4 2014 ) Array ( [0] => Chevrolet Avalanche 2006 ) Array ( [0] => Chevrolet Silverado (standard key) 2008 ) Array ( [0] => Toyota RAV4 2013 ) Array ( [0] => Honda CR-V 2013 ) Array ( [0] => Ford Fusion 2006 ) Array ( [0] => Ford Mustang [1] => Manual Trans ) // No year here Array ( [0] => Dodge Ram Pickup 2014 ) Array ( [0] => Subaru Legacy 2013 ) Array ( [0] => Mercury Mountaineer 2005 ) Array ( [0] => Toyota Prius [1] => PTS ) // No year here Array ( [0] => Honda Pilot 2010 ) Array ( [0] => Pontiac G6 2007 ) Array ( [0] => Jeep Wrangler 2011 ) Array ( [0] => Honda Accord (standard key) 2011 ) Array ( [0] => Kia Sorento 2014 ) Array ( [0] => Buick Rendezvous 2005 ) Array ( [0] => Mercury Marauder 2004 ) Array ( [0] => Honda CR-V 2015 ) Array ( [0] => Toyota Camry 2008 ) Array ( [0] => Mercury Sable 2002 ) Array ( [0] => Toyota FJ Cruiser 2011 ) Array ( [0] => Chrysler Concorde 2004 ) Array ( [0] => Honda Accord (standard key) [1] => Manual Trans ) // No year here Array ( [0] => Chevrolet HHR 2011 )
-
Thank you. I think I may have left out a critical part to the examples, seeing how things are returned in your code. The thing is that not every row will have words after the 4 digit year. So testing with your code like this foreach($rows as $row) { $parts = preg_split('/[0-9]{4}/', $row['vehicle']); //print_r($parts); preg_match_all('/(.*[0-9]{4})\s+(.*)/', $row['vehicle'],$parts); print_r($parts); //echo 'up to and including the 4 digit number - ' . $parts[1][0] . '<br>'; //echo 'after the 4 digit number - ' . $parts[2][0]; echo '<br><br>'; } I end up with an array like this, missing all info for cars that don't have words after the year. Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( [0] => Nissan Quest 2014 PTS ) [1] => Array ( [0] => Nissan Quest 2014 ) [2] => Array ( [0] => PTS ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( [0] => Subaru Legacy 2014 Manual Trans ) [1] => Array ( [0] => Subaru Legacy 2014 ) [2] => Array ( [0] => Manual Trans ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( [0] => Infiniti M35 / M45 2007 PTS ) [1] => Array ( [0] => Infiniti M35 / M45 2007 ) [2] => Array ( [0] => PTS ) ) Array ( [0] => Array ( [0] => Toyota Highlander 2015 PTS ) [1] => Array ( [0] => Toyota Highlander 2015 ) [2] => Array ( [0] => PTS ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( [0] => Ford Mustang 2013 Manual Trans ) [1] => Array ( [0] => Ford Mustang 2013 ) [2] => Array ( [0] => Manual Trans ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( [0] => Toyota Prius 2005 PTS ) [1] => Array ( [0] => Toyota Prius 2005 ) [2] => Array ( [0] => PTS ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) Array ( [0] => Array ( [0] => Honda Accord (standard key) 2014 Manual Trans ) [1] => Array ( [0] => Honda Accord (standard key) 2014 ) [2] => Array ( [0] => Manual Trans ) ) Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) I tried the PREG_SPLIT_DELIM_CAPTURE on the preg_split but that too for whatever reason did not return the year as a array element like it says it would. That resulted in this array (commenting out the preg_match_all() too) Array ( [0] => Chrysler 300 (standard key) [1] => ) Array ( [0] => Ford Fusion [1] => ) Array ( [0] => Nissan Quest [1] => PTS ) Array ( [0] => Jeep Liberty [1] => ) Array ( [0] => Pontiac Sunfire [1] => ) Array ( [0] => Subaru Legacy [1] => ) Array ( [0] => Buick Lucerne [1] => ) Array ( [0] => Saturn Ion [1] => ) Array ( [0] => Ford Escape (standard key) [1] => ) Array ( [0] => Chevrolet Cruze (flip key) [1] => ) Array ( [0] => Acura MDX [1] => ) Array ( [0] => Subaru Impreza [1] => ) Array ( [0] => Ford Focus (standard key) [1] => ) Array ( [0] => Toyota Corolla [1] => ) Array ( [0] => Nissan Murano [1] => ) Array ( [0] => Honda CR-V [1] => ) Array ( [0] => Toyota Yaris [1] => ) Array ( [0] => Chevrolet Silverado (standard key) [1] => ) Array ( [0] => Subaru Legacy [1] => Manual Trans ) Array ( [0] => Volkswagen Routan [1] => ) Array ( [0] => Ford Crown Vic [1] => ) Array ( [0] => Infiniti M35 / M45 [1] => PTS ) Array ( [0] => Toyota Highlander [1] => PTS ) Array ( [0] => Ford Edge (standard key) [1] => ) Array ( [0] => Nissan Titan [1] => ) Array ( [0] => Toyota RAV4 [1] => ) Array ( [0] => Chevrolet Avalanche [1] => ) Array ( [0] => Chevrolet Silverado (standard key) [1] => ) Array ( [0] => Toyota RAV4 [1] => ) Array ( [0] => Honda CR-V [1] => ) Array ( [0] => Ford Fusion [1] => ) Array ( [0] => Ford Mustang [1] => Manual Trans ) Array ( [0] => Dodge Ram Pickup [1] => ) Array ( [0] => Subaru Legacy [1] => ) Array ( [0] => Mercury Mountaineer [1] => ) Array ( [0] => Toyota Prius [1] => PTS ) Array ( [0] => Honda Pilot [1] => ) Array ( [0] => Pontiac G6 [1] => ) Array ( [0] => Jeep Wrangler [1] => ) Array ( [0] => Honda Accord (standard key) [1] => ) Array ( [0] => Kia Sorento [1] => ) Array ( [0] => Buick Rendezvous [1] => ) Array ( [0] => Mercury Marauder [1] => ) Array ( [0] => Honda CR-V [1] => ) Array ( [0] => Toyota Camry [1] => ) Array ( [0] => Mercury Sable [1] => ) Array ( [0] => Toyota FJ Cruiser [1] => ) Array ( [0] => Chrysler Concorde [1] => ) Array ( [0] => Honda Accord (standard key) [1] => Manual Trans ) Array ( [0] => Chevrolet HHR [1] => ) More help please!
-
I have a database with vehicle info that I want to split some of the text off the end of the vehicle name. Example: Subaru WRX 2010 Manual Trans I want to split it into 2 parts like this array(0 => Subaru WRX 2010, 1 => Manual Trans) So basically I want to split it right after the year in the string. Now the other problem is that the year is not always the 3rd thing in the name. Another example would be Chevy SIlverado (standard key) 2011 Automatic. I tried preg_split but I loose the year in the returned array cause I was trying something like this $parts = preg_split('/[0-9]{4}/', $row['vehicle']); Like many people I am terrible at regex. I have watched some videos and messed around for a while but can't figure out how to split it AFTER the 4 digit year only. Any help is appreciated!
-
You don't have control over what google will display in the SERPs. They don't just use the description tags and header tags from your site. They use any and all content it finds to build the preview and can build that how ever they please based on the search term typed.
-
Without knowing the exact end result and the exact content you are wanting to put in the footer it's hard to say the exact route you should take on this. But I would start by putting the footer inside the main wrapper since it has the same width anyway and get rid of the width rules on the footer and divs within it. I always used 990px for width if I was doing a static width site. You should also switch to the newer html5 doctype. I also get a 404 error for the global.js file.
-
MySQL Replication with localserver to remote server
fastsol replied to niranjana06's topic in MySQL Help
You just need to use the "export" button in the menu to create a sql file that you can then "import" in to the new database and it will build everything the same.- 1 reply
-
- replication
- mysql
-
(and 1 more)
Tagged with:
-
I think you're using the wrong var in your frwite(). You open the file with the handle of $fh but then try to use the $fname in the function to write it. Try this fwrite($fh,$data); Example info http://php.net/manual/en/function.fwrite.php
-
I just confirmed, the issue is your delcaration of the 1000px.
-
Here is a great tutorial series on how to build it with ajax. https://www.youtube.com/playlist?list=PLfdtiltiRHWHCzhdE0N1zmeFHlEuqxQvm
- 3 replies
-
- 1
-
- upload
- progressbar
-
(and 1 more)
Tagged with:
-
Help for writing code without mysql_result
fastsol replied to yathrakaaran's topic in PHP Coding Help
I find it easier to add a AS to the COUNT and return it as a normal table column name. Then you just use normal fetching on the query. $total_results = mysqli_query($mysqli,"SELECT COUNT(*) AS `count` FROM gallery_photos WHERE category_name='" . addslashes($category_name) . "'"); if (!$total_results) { die('Could not query:' . mysqli_error()); } $row = mysqli_fetch_assoc($total_results); $total_results = $row['count']; -
Well this is new. Interesting problem with fulltext search and pagination.
fastsol replied to man5's topic in PHP Coding Help
This is just as easy to do by checking if the search term has a value. By using the submit check, now you just made your script need to retain that in the url rather than just the info you truly need, the search term. -
This is as dynamic as it could be but since you haven't really provided much info to understand what this is going to be used for and how. This should work based on your example. $next = array( pic1 => array('slide' => ($current + 1)), pic2 => array('slide' => ($current + 2)), pic3 => array('slide' => ($current + 3)));
-
duplicate records are getting inserted in the database
fastsol replied to subhomoy's topic in PHP Coding Help
Are you sure you're setting the IPN output to verified in the test console? Or are you running an actual test transaction like a customer would if it was live? -
duplicate records are getting inserted in the database
fastsol replied to subhomoy's topic in PHP Coding Help
You're saying the latest script you posted gives you INVALID or the script you've been working on gives you INVALID? I don't really see any issues with the recent script, but I know that there are a couple versions of the IPN scripts floating around the net that are old and won't work, so maybe this is one of them. I only use the examples that PayPal provides since those will be the most up to date versions of what they require or reccommend. -
duplicate records are getting inserted in the database
fastsol replied to subhomoy's topic in PHP Coding Help
Yes that is much better, but still has some issues with the check_txn_id(). You're trying to bindParam on $transaction_id but you defined $txn_id. Also you're trying to call $this which doesn't exist. You need to pass the db object to the function for it to work. Lastly, your check_txn_id function itself should be towards the top of the page, php reads top-to-bottom, so you'll try to call on a function that hasn't been defined until later, so that won't work. -
Because you're tryning to call it on class="token" but in the html you use id="token". You need to change one or the other.
-
What is the html for the element with class token?
-
Available products by manufacturer display in select element
fastsol replied to Nickmadd's topic in PHP Coding Help
No, the concept is the same whether it's cars or whatever. Granted you can design it however you want, but you'll find that in the long run you'll face many more challenges when wanting to modify how you get certain data or want to manipulate that data in different ways than you originally thought. You may think "oh I just want to get that data and display it on the page quickly" but then in 2 months you go "boy it would be nice to also do XXX with that data" but now it's a pain cause the overall design structure is flawed. In your case using cars, you would want I think 4 overall tables to control all this: vehicle_makes vehicle_models vehicle_years products The produtcs table would then have a column of like year_model_id that woudl be a referrence to the id column of the vehicle_years table so that you can relate the product (in your case a specific car that is for sale of a 2002 chevy silverado) to a specific make, model and year value in the other tables. Now this does start to get a little complex joining all these tables together if you haven't ever done this kind of thing but it's really the best way to go about it for the long run. If you ask me nicely in a PM I might be able to give you such a database file that already has the vehicle parts done. -
Available products by manufacturer display in select element
fastsol replied to Nickmadd's topic in PHP Coding Help
You're thinking to broad in that respect. It's unlikely that and entire brands worth of products is out of stock unless you literally only have one product per brand which makes no sense. It's very likely that you will have certain products that are out of stock though. So I put a "active" column in the products table and use a boolean value to decide if it's active or not. You could certainly do the same concept for the brands table but unless you want to turn off the entire brands worth of products you wouldn't generally turn off a brand, but rather just the products themselves that are out of stock. To do a products type website you generally woud have at least 5 tables to construct it properly. You could have more depending on how you abstract other details about the products them selves. -
I found PDO to be easier and easier to convert too.