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

Red Hat Enterprise Linux 7.3 Beta Adds NVDIMM Support, Improves Security

Today, August 25, 2016, Red Hat announced that version 7.3 of its powerful Red Hat Enterprise Linux operating system is now in development, and a Beta build is available for download and testing. Red Hat Enterprise Linux 7.3 Beta brings lots of improvements and innovations, support for new hardware devices, and improves the overall security of the Linux kernel-based operating system used by some of the biggest enterprises and organizations around the globe. Among some of the major new features implemented in the Red Hat Enterprise Linux 7.3 release, we can mention important networking improvements, and support for Non-Volatile Dual In-line Memory Modules (NVDIMMs). Read more Also: CentOS 6 Linux OS Receives Important Kernel Security Update from Red Hat Release of Red Hat Virtualization 4 Offers New Functionality for Workloads

Ubuntu 16.10 Beta 1 Released, Available to Download Now

The Ubuntu 16.10 Beta 1 releases are now available to download. You know the drill by now: {num} Ubuntu flavors, some freshly pressed ISOs, plenty of new bugs to find and no guarantees that things won’t go boom. Read more Also: Ubuntu 16.10 Beta Launches for Opt-in Flavors, Adds GCC 6.2 and LibreOffice 5.2

Games for GNU/Linux

PC-BSD Becomes TrueOS, FreeBSD 11.0 Reaches RC2

  • More Details On PC-BSD's Rebranding As TrueOS
    Most Phoronix readers know PC-BSD as the BSD operating system derived from FreeBSD that aims to be user-friendly on the desktop side and they've done a fairly good job at that over the years. However, the OS has been in the process of re-branding itself as TrueOS. PC-BSD has been offering "TrueOS Server" for a while now as their FreeBSD-based server offering. But around the upcoming FreeBSD 11.0 release they are looking to re-brand their primary desktop download too now as TrueOS.
  • FreeBSD 11.0-RC2 Arrives With Fixes
    The second release candidate to the upcoming FreeBSD 11 is now available for testing. FreeBSD 11.0-RC2 ships with various bug fixes, several networking related changes, Clang compiler fixes, and other updates. FreeBSD 11.0 is bringing updated KMS drivers, Linux binary compatibility layer improvements, UEFI improvements, Bhyve virtualization improvements, and a plethora of other work. Those not yet familiar with FreeBSD 11 can see the what's new guide.