Language Selection

English French German Italian Portuguese Spanish

Learn PHP - Getting dynamic

Filed under
Software

The whole point of coding in PHP instead of just using HTML files is to make everything dynamic. You want the pages to make themselves, so you can spend more time counting your loot. The ideal way to get content onto your pages is from a database. First of all, databases are, as the name suggests, great places to store data. Secondly, clients pay more if you use the words "database" and "dynamic" in the quote and invoice.

First off, we need to get our PHP program talking to the database. The primary time-waster when querying databases is waiting for the darn thing to establish a connection, so we'll do that right at the start and get it over with. We'll do this in a function so that you can type all this out once and just use it over and over, thus saving more time for sending out bills for your web development work:

function dbconnect($dbserver,$dbusername,$dbpassword,$dbname) {
$connection=mysql_connect($dbserver,$dbusername,$dbpassword) or die(mysql_error);
$db=mysql_select_db($dbname,$connection) or die(mysql_error());
}

The first line establishes the connection, and the second line selects the tectonic database. The die(mysql_error()) will display any errors and stop the program from executing further if something goes terribly, terribly wrong.
When you want to call this function, you'd use something like this:


dbconnect('localhost','tectonicdbuser','topsecret','tectonic');

Every time you call this function you will be instantly and magically connected to your database until you either explicitly disconnect or the page finishes processing. I don't bother to disconnect because, well, I'm lazy.

Right, now we want to get some info out of the database. We'll use the unique id number to identify which story we want, and go grab it before anyone notices.

Full Article.

More in Tux Machines

Linux 4.2 Bringing Support For ARCv2, HS38 CPU Cores

The ARC architecture updates for the Linux 4.2 kernel have landed. With the ARC architecture updates in Linux 4.2 comes support for HS38 cores, which in turn are based on the Synopsys next-gen ISA known as ARCv2. The ARCv2 ISA is faster and more feature-rich than their original instruction set architecture. The HS38 cores have a 10-stage pipeline core with MMU support, SMP up to four cores, and other new features. The HS38 processor is still 32-bit and is "optimized for high-performance embedded applications running Linux." Read more Also: Radeon & AMDGPU DRM Fixes Queue Up For Linux 4.2

Ubuntu Touch OTA-5 Will Bring a New Thumbnailer in Unity 8, Support for Refunds

Canonical's Alejandro J. Cura had the great pleasure of reporting a few hours ago that the upcoming OTA-5 update for the Ubuntu Touch mobile operating system will get some attractive new features in the Unity 8 user interface. Read more

The July 2015 issue of the PCLinuxOS Magazine

With the exception of a brief period in 2009, The PCLinuxOS Magazine has been published on a monthly basis since September, 2006. The PCLinuxOS Magazine is a product of the PCLinuxOS community, published by volunteers from the community. The magazine is lead by Paul Arnote, Chief Editor, and Assistant Editor Meemaw. The PCLinuxOS Magazine is released under the Creative Commons Attribution-NonCommercial-Share-Alike 3.0 Unported license, and some rights are reserved. Read more

The Linux Setup - Neil McGovern, Debian Project Leader

I’m the current Debian Project Leader—which is a very impressive title that boils down to being a figurehead for the Debian project. I first started getting involved with Debian in 2003, and have wended my way through various roles in the project, from designing t-shirts to being the Release Manager for the last three releases, Lenny, Squeeze and Wheezy. In my day job, I’m the engineering manager for Collabora, an open source software consultancy which is fairly similar—basically making sure that all the engineers are happy and helping unblock any problems that come along. Read more