I’m deciding whether to use if/else vs switch/case in a PHP site that I am writing and I was wondering if there were any benefits to using one or the other or if there were certain instances where one was intended to be used rather than the other. Answer Interesting question because in a compiled langua…
PHP pagination does not recognize $page
I have downloaded the pagination code and used it for my website running on my local machine. After modifying and testing, there was a problem where it does not recognize the variable $page. Please refer to the following code: This is the error it generated: How can I fix this error? Answer This won’t w…
How to check if ID in database exists
Why won’t this send the user to user.php if the ID don’t exist in the table? Answer Try something like this :). http://php.net/manual/en/function.mysql-num-rows.php
Validate PHP syntax in VIM
I would like to know how if it’s possible to validate if a PHP file is valid in VIM without closing VIM every time? Thank you Answer You can execute shell commands in vim. This is the same as calling php -l filename.php from the shell: I have this mapped into my ~/.vim/after/ftplugin/php.vim file so tha…
What’s more efficient – storing logs in sql database or files?
I have few scripts loaded by cron quite often. Right now I don’t store any logs, so if any script fails to load, I won’t know it till I see results – and even when I notice that results are not correct, I can’t do anything since I don’t know which script failed. I’ve decide…
Extending ArrayObject in PHP properly?
Problem: I am trying to extend PHP’s ArrayObject as shown below. Unfortunately I can’t get it to work properly when setting multi-dimensional objects and instead an error thrown as I have the strict settings enabled in PHP. (Error: Strict standards: Creating default object from empty value) Questi…
In PHP, what happens in memory when we use mysql_query
I used to fetch large amount of data using mysql_query then iterating through the result one by one to process the data. Ex: Recently I looked at a few framework and realized that they fetched all data to an array in memory and returning the array. I would like to know the pros/cons of each method. It appears…
IMDB to MySQL: Insert IMDB data into MySQL database
I’m looking for a solution to import all the IMDB data into my own MySQL database. I’ve downloaded all the IMDB data files from their homepage which are all in the file format *.list (in Windows). I want to retrieve and that information and insert it correctly into my MySQL database so I can do some test and …
check for existing, persistent SQLite connection in PHP
PHP supports the use of persistent SQLite connection. However, problem arises in trying to run maintenance scripts (like file backup), with such a connection opened. These scripts are likely to be run without a server restart every now and then, on periods of low traffic. The question is : How to check if the…
Upload website + database to dropbox with PHP
Does anyone know, if it’s possible to backup my website and database to a dropbox account with php or something? And if it’s possible, how can I do it the best way? 🙂 Best Regards Simon