I contacted the host of my project for a problem I was having with inserting data from a form into a db on their server. One of the answers they gave me was:

...for future reference, never declare a prefix, always leave this option blank.

I understand what a prefix is in English grammar, but what does it mean in php code? I have been teaching myself php with tutorials and none of them have mentioned this term. I hadn't even realized that I had even used a prefix. I was just modifying code that I found in tutorials based on on current needs and on advice from people here.

Dani AI

Generated

Clarification: in this thread "prefix" is not a PHP language feature but a naming prefix applied to databases or tables. As pointed out, many shared hosts or control panels prepend an account/user string to database names so names stay unique across customers. That behavior is part of the hosting/MySQL environment, not something PHP enforces.

Separate concept: many PHP applications let an installer set a table prefix (a short string added to every table name). Table prefixes are useful to run multiple installs in one database or to avoid name collisions, but they are not a security fix. Proper prevention of SQL injection and permission errors requires parameterized queries (prepared statements), correct user privileges, and careful error checking—not reliance on a prefix.

Practical notes and troubleshooting steps that follow from the above. Prefer simple names composed of letters, numbers and underscores; avoid embedding a full domain or using hyphens (hyphens require quoting in SQL and make queries fiddlier). If a host added an account prefix already, use the exact full database name shown in the control panel in the PHP connection settings and confirm the DB user has INSERT privileges. When inserts fail, enable error reporting, check the connection string, confirm the exact database and table names, and inspect the SQL error message. This aligns with 's explanation and addresses 's concern about including a domain name in the database name.

Recommended Answers

All 5 Replies

...for future reference, never declare a prefix, always leave this option blank.

May be they are talking about the prefix while creating a database. For example, if your host is somehost, it will add prefix somehost_databasename while creating a database. I guess thats what they mean by that.

Hmm, yeah, that does seem to fit. It was the first database that I set up, so I was winging it when I made the name, and I did put the domain name in the database name. Later, I thought that I shouldn't have done that, looks bad in my oppinion.

yeah.. its confusing sometimes and most of the time, you tend to forget that you have a prefix !!

Thanks for clarifying that for me.

I named my db:
befit4riding_com_-_journal.
You are saying that the is not necesarry, correct?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.