
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Is there PHP basename() equivalent in MySQL?
If given a string containing a path to a file, the PHP basename() function will return the base name of the file. To get its equivalent in MySQL, you can use SUBSTRING_INDEX(). Let us first create a table −
mysql> create table DemoTable -> ( -> Location varchar(200) -> ); Query OK, 0 rows affected (1.02 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('C:\Web\Sum.java'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('E:\WebDevelopment\Image1.png'); Query OK, 1 row affected (0.42 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+------------------------------+ | Location | +------------------------------+ | C:\Web\Sum.java | | E:\WebDevelopment\Image1.png | +------------------------------+ 2 rows in set (0.00 sec)
Following is the query to work with the basename() equivalent in MySQL and get what the basename() function returns i.e. the base name of the file −
mysql> select Location, -> SUBSTRING_INDEX(Location,'\', -1) AS NameOfFile from DemoTable;
Output
+------------------------------+------------+ | Location | NameOfFile | +------------------------------+------------+ | C:\Web\Sum.java | Sum.java | | E:\WebDevelopment\Image1.png | Image1.png | +------------------------------+------------+ 2 rows in set (0.00 sec)
- Related Articles
- basename( ) function in PHP
- What is the PHP stripos() equivalent in MySQL?
- What is the PHP equivalent of MySQL's UNHEX()?
- Is there an equivalent of C’s “?:” ternary operator in Python?
- What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?
- Is their a JavaScript Equivalent to PHP explode()?
- Is there a Microsoft equivalent for HTML5 Server-Sent Events?
- What is the equivalent of EXCEPT in MySQL?
- What is the MySQL SELECT INTO Equivalent?
- PHP equivalent of friend or internal
- Is there something available in Python like PHP autoloader?
- ROW_NUMBER() equivalent in MySQL for inserting?
- Is there anything like substr_replace in MySQL?
- Is there any alternative for CONCAT() in MySQL?
- Is there a way to change the date format in php?

Advertisements